import { requestClient } from '#/api/request';

export namespace ProjectMemberApi {
  export interface Member {
    id?: number;
    name: string;
    role: string;
    projectId: number;
    sex?: string;
    email?: string;
    [key: string]: any;
  }

  export interface SaveParams extends Member {}
  export interface UpdateParams extends Member {}

  export interface ListParams {
    page?: number;
    pageSize?: number;
    searchKey?: string;
    role?: string;
    sex?: string;
    email?: string;
  }

  export interface ListResult {
    data: Member[];
    total: number;
  }
}

/**
 * 获取成员列表（分页+查询）
 */
export function getProjectMemberListApi(params: ProjectMemberApi.ListParams) {
  return requestClient.post<ProjectMemberApi.ListResult>('/project/member/list', params);
}

/**
 * 获取成员详情
 */
export function getProjectMemberDetailApi(id: number | string) {
  return requestClient.get(`/project/member/get?id=${id}`);
}

/**
 * 新增成员
 */
export function saveProjectMemberApi(data: ProjectMemberApi.SaveParams) {
  return requestClient.post('/project/member/save', data);
}

/**
 * 更新成员
 */
export function updateProjectMemberApi(data: ProjectMemberApi.UpdateParams) {
  return requestClient.put('/project/member/update', data);
}

/**
 * 删除成员
 */
export function deleteProjectMemberApi(id: number | string) {
  return requestClient.delete(`/project/member/delete?id=${id}`);
}
